import socket
from fastapi import APIRouter, Depends
from appAccounts.utils.sec_utils import token_validate_v2, oauth2_scheme
from appAccounts.utils import accounts_utl
from appAccounts.schemas import accounts

host_name = socket.gethostname()
ip_address = socket.gethostbyname(host_name)

router = APIRouter()

@router.get("/accounts/health")
async def health_check():
    return {"Hello": f"World appAccounts from {host_name}({ip_address})"}

@router.post("/accounts/process_data")
async def process_data(data: dict):
    processed_data = {key: value.upper() for key, value in data.items()}
    return processed_data

@router.post("/accounts/account")
async def create_account(account: accounts.sAccountCreate, acc_token: str = Depends(oauth2_scheme)):
    token_validate_v2(acc_token, account.cust_id)
    return await accounts_utl.create_account(acc_token, newaccount=account)

@router.patch("/accounts/account")
async def update_account(account: accounts.sAccountModify, acc_token: str = Depends(oauth2_scheme)):
    token_validate_v2(acc_token, account.cust_id)
    return await accounts_utl.modify_account(acc_token, updaccount=account)

@router.delete("/accounts/account")
async def create_account(account: accounts.sAccountsDelete, acc_token: str = Depends(oauth2_scheme)):
    token_validate_v2(acc_token, account.cust_id)
    return await accounts_utl.close_account(acc_token, closeaccount=account)

@router.get("/accounts")
async def show_all_accounts(account: accounts.sAccountsGet, acc_token: str = Depends(oauth2_scheme)):
    token_validate_v2(acc_token, account.cust_id)
    return await accounts_utl.get_all_accounts(acc_token, getaccounts=account)